<div class="ui basic segment">
  <h1 class="ui dividing header">
    <%= link("Podcasts", to: ~p"/admin/podcasts") %>
    <%= render(PodcastView, "_dropdown_list.html", assigns) %>
    <%= link @episode.podcast.name, to: ~p"/admin/podcasts/#{@episode.podcast.slug}/episodes" %>
    &raquo;
    <%= link @episode.slug, to: ~p"/admin/podcasts/#{@podcast.slug}/episodes/#{@episode.slug}/edit" %>

    <div class="ui basic right floated buttons">
    <%= if @episode.published do %>
      <input type="hidden" value="<%= Changelog.Buffer.Content.episode_text(@item) %>">
      <button class="ui icon button clipboard" title="Copy Share Text"><i class="share icon"></i></button>
      <%= link("View Public",
        to: ~p"/#{@podcast.slug}/#{@episode.slug}",
        rel: "external",
        class: "ui button") %>
    <% else %>
      <%= link("Preview",
        to: ~p"/#{@podcast.slug}/#{@episode.slug}/preview",
        rel: "external",
        class: "ui button") %>
    <% end %>
    <%= if @item do %>
      <%= link("News Item", to: ~p"/admin/news/items/#{@item}/edit", class: "ui button") %>
    <% end %>
    </div>

    <div class="sub header"><%= @episode.title %></div>
  </h1>
</div>

<div class="ui basic segment">
  <div class="ui equal width grid">
    <div class="column">
      <h2 class="ui header">Embed via JS</h2>
      <div class="ui fluid action input">
        <input type="text" value="<%= embed_code(@episode) %>">
        <button class="ui basic icon clipboard button"><i class="clipboard icon"></i></button>
      </div>
    </div>

    <div class="column">
      <h2 class="ui header">Embed via Frame</h2>
      <div class="ui fluid action input">
        <input type="text" value="<%= embed_iframe(@episode, "night") %>">
        <button class="ui basic icon clipboard button"><i class="clipboard icon"></i></button>
      </div>
    </div>
  </div>

<%= if Enum.any?(@stats) do %>
  <h2 class="ui header">Stats</h2>

  <div class="ui centered stackable grid">
    <div class="ui four wide column">
      <div class="ui horizontal statistics">
        <div class="statistic">
          <div class="value"><%= SharedHelpers.pretty_downloads(@episode) %></div>
          <div class="label">Downloads</div>
        </div>

        <div class="statistic">
          <div class="value"><%= SharedHelpers.comma_separated(@episode.email_sends) %></div>
          <div class="label">Emails Sent</div>
        </div>
        <div class="statistic">
          <div class="value"><%= SharedHelpers.comma_separated(@episode.email_opens) %></div>
          <div class="label">Emails Opened</div>
        </div>
        <div class="statistic">
          <div class="value"><%= SharedHelpers.percent(@episode.email_opens, @episode.email_sends) %>%</div>
          <div class="label">Open Rate</div>
        </div>
        <div class="statistic">
          <div class="value"><%= length(@stats) %></div>
          <div class="label">Days Published</div>
        </div>
      </div>
    </div>

    <div class="ui twelve wide column">
      <div class="chart" data-chart="<%= line_chart_data(@stats) %>"></div>
    </div>
  </div>
<% end %>
